<?php include dirname(__FILE__).'/common/header.php'; ?>

<?php include dirname(__FILE__).'/common/menu.php'; ?>

var attr = {};
attr.ctrlName = '<?php echo $ctrlName; ?>';

function loadOneData(data,i) {
    Ext.get(document.body).mask('正在加载第['+(i+1)+'/'+data.length+']用户');
    if(i >= data.length) {
        Ext.get(document.body).unmask();
        list.grid.reload();
        return;
    }
    var r = data[i];
    ZM.ajax({
        url: list.siteUrl + 'api_football_game/initCustomer',
        params:{openid:r.openid, nickname:r.nickname, sex: r.sex,province: r.province,city:r.city,country:r.country,headimgurl:r.headimgurl},
        success:function(res){
            ZM.ajax({
                url: list.siteUrl + 'api_football_game/submitScore',
                params:{game_score: parseInt(Math.random()*100)+200},
                success:function(res){
                    loadOneData(data,i+1);
                }
            });
        }
    });
}
/*
| -------------------------------------------------------------------
|  List Grid
| -------------------------------------------------------------------
*/
list.grid = new ZM.GridPanel({
    url: list.baseUrl + attr.ctrlName+'/getCustomerList',
    tbar:[{
        text:'导出过滤顾客',
        cls:'btn-show',
        hidden:!Ext.permission[attr.ctrlName + '/exportCustomerList'.toLowerCase()],
        handler:function() {
            var sortInfo = list.grid.store.getSortState();
            if(sortInfo) {
                list.grid.store.baseParams['sort'] = sortInfo['field'];
                list.grid.store.baseParams['dir'] = sortInfo['direction'];
            }
            location.href = list.baseUrl + attr.ctrlName + '/exportCustomerList?'+ Ext.urlEncode(list.grid.store.baseParams);
        }
    },'-',{
        text:'导入数据',
        cls:'btn-show',
        hidden:!Ext.permission[attr.ctrlName + '/exportCustomerList'.toLowerCase()],
        handler:function() {
            var win = new ZM.PopUp({
                title:'添加时间设置',
                defaults:{labelWidth: 120},
                items:{
                    xtype:'formpanel',
                    url:list.baseUrl+ attr.ctrlName+'/getSomeData',
                    success:function(res) {
                        //console.log(res);
                        win.hide();
                        loadOneData(res.items,0);
                    },
                    items:[{
                        xtype:'numberfield',
                        fieldLabel:'起点',
                        name:'start',
                        allowBlank:false
                    },{
                        xtype:'numberfield',
                        fieldLabel:'长度',
                        name:'limit',
                        value: 50,
                        allowBlank:false
                    }]
                }
            }).show();
        }
    }],
    columns:[
        {header:'ID',dataIndex:'customer_id',filter:{}},
        {header:'头像',width:120,dataIndex:'headimgurl',renderer:ZM.cellImage},
        {header:'昵称',dataIndex:'nickname',filter:{}},
        {header:'openid',dataIndex:'openid',width:200,filter:{}},
        {header:'性别',dataIndex:'sex',filter:{xtype:'combofield',options:[['','全部'],['0','未知'],[1,'男'],[2,'女']]},renderer:function(val) {
            return ZM.id2name(val,[[0,'未知'],[1,'男'],[2,'女']]);
        }},
        {header:'省份',dataIndex:'province'},
        {header:'城市',dataIndex:'city'},
        {header:'国家',dataIndex:'country'},
        {header:'创建时间',dataIndex:'customer_time_create',width:140,filter:{xtype:'daterangefield'}},
        {header:'游戏次数',dataIndex:'game_times',sort:true},
        {header:'最高分',dataIndex:'game_max_score',sort:true},
        {header:'最高分时间',dataIndex:'customer_max_score_time_create',sort:true,filter:{xtype:'daterangefield'}}
    ]
});
/*
| -------------------------------------------------------------------
|  List Grid Action
| -------------------------------------------------------------------
*/
list.grid.fireDisable = function(r) {
    var r = r.json;
    Ext.Msg.confirm('确认?','确定要禁用顾客['+r.nickname+']?',function(btn) {
        if(btn != 'no') {
            ZM.ajax({
                url: list.baseUrl + attr.ctrlName+'/disableCustomer',
                params:{customer_id:r.customer_id},
                mask:list.grid,
                success:function(res){
                    ZM.bo.msg('success!',res.detail);
                    list.grid.store.reload();
                }
            });
        }
    });
}

list.grid.fireEnable = function(r) {
    var r = r.json;
    Ext.Msg.confirm('确认?','确定要激活顾客['+r.nickname+']?',function(btn) {
        if(btn != 'no') {
            ZM.ajax({
                url: list.baseUrl + attr.ctrlName+'/enableCustomer',
                params:{customer_id:r.customer_id},
                mask:list.grid,
                success:function(res){
                    ZM.bo.msg('success!',res.detail);
                    list.grid.store.reload();
                }
            });
        }
    });
}

<?php include dirname(__FILE__).'/common/layout.php'; ?>
list.grid.store.load();
<?php include dirname(__FILE__).'/common/footer.php'; ?>